<template>
  <div class="app-container">
    <Ht-search-form
      v-show="showSearch"
      :advOptions="[]"
      :dictMap="dictMapAsync"
      :formOptions="formOptions"
      :outputQueryParams="queryParams"
      :queryParams="queryParams"
      :beforeSearchCallback="false"
      @beforeSearchCallback="beforeSearchCallback"
      :clearCallBack="clearCallBack"
    >
      <template slot="endSlotOption">
        <amount-range-search label="金额区间" ref="amountRangeSearch"></amount-range-search>
      </template>
    </Ht-search-form>

    <ht-table
      ref="dataTable"
      :dictMap="dictMap"
      :multi-select="false"
      :opButtonList="opButtonList"
      :queryParams="queryParams"
      :reqConfig="regConfig"
      :showSerialNumber="false"
      :tableBindColumns="tableBindColumns"
      :randomRowKey="true"
    >
      <template v-slot:operate>
        <el-table-column align="left" fixed="right" label="操作" width="50">
          <template slot-scope="scope">
            <ht-button-group
              :buttonList="[
                {
                  label: '明细',
                  doFunc: () => {
                    handleAction('detail', scope.row);
                  },
                },
              ]"
            />
          </template>
        </el-table-column>
      </template>
    </ht-table>

    <!-- 添加或修改弹出框 -->
    <el-dialog
      :close-on-click-modal="false"
      :title="title"
      center
      :visible.sync="open"
      v-if="open"
      append-to-body
      width="1024px"
    >
      <el-form ref="detailForm" :disabled="true" :model="detailForm" label-width="120px">
        <el-card class="form-card txnInfo-card">
          <div slot="header" class="label-header-msg">
            <span>业务查询信息详情</span>
          </div>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="查询流水号" prop="id">
                <el-input v-model="detailForm.id" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="原交易流水/批次号" prop="oriId">
                <el-input v-model="detailForm.oriId" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="内部机构号" prop="brno">
                <el-select style="width: 100%" v-model="detailForm.brno" placeholder="内部机构号">
                  <el-option
                    v-for="dict in dictMap['Cnaps2Dict.CP2_BRNO']"
                    :key="dict.value"
                    :label="`${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="报文标识号" prop="pkgid">
                <el-input v-model="detailForm.pkgid" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="来往标识" prop="drct">
                <el-select style="width: 100%" v-model="detailForm.drct" placeholder="来往标识">
                  <el-option
                    v-for="dict in dictMap.DRCTCODE"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="系统编号" prop="sysCode">
                <el-select style="width: 100%" v-model="detailForm.sysCode" placeholder="系统编号">
                  <el-option
                    v-for="dict in dictMap.ORGAN_SYSTYPE_310"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="工作日期" prop="workdate">
                <el-date-picker v-model="detailForm.workdate" style="width: 100%" type="date" value-format="yyyyMMdd" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="CPG日期" prop="vdate">
                <el-date-picker v-model="detailForm.vdate" style="width: 100%" type="date" value-format="yyyyMMdd" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="发起间接参与机构" prop="queryIndirect">
                <el-input v-model="detailForm.queryIndirect" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="发起直接参与机构" prop="directSender">
                <el-input v-model="detailForm.directSender" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="发起参与机构名称" prop="queryIndirectName">
                <el-input v-model="detailForm.queryIndirectName" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="接收间接参与机构" prop="directRecver">
                <el-input v-model="detailForm.directRecver" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="接收直接参与机构" prop="reviewIndirect">
                <el-input v-model="detailForm.reviewIndirect" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="接收参与机构名称" prop="reviewIndirectName">
                <el-input v-model="detailForm.reviewIndirectName" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="查询类型" prop="inqType">
                <el-select style="width: 100%" v-model="detailForm.inqType" placeholder="查询类型">
                  <el-option
                    v-for="dict in dictMap.INQ_TYPE_314_QUERY"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="原发起参与机构号" prop="oriSender">
                <el-input v-model="detailForm.oriSender" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="原报文标识号" prop="oriPkgid">
                <el-input v-model="detailForm.oriPkgid" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="原报文类型" prop="oriMsgType">
                <el-select
                  style="width: 100%"
                  v-model="detailForm.oriMsgType + '-' + detailForm.oriMsgTypeDesc"
                  placeholder="原业务类型"
                ></el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="原明细标识号" prop="oriDtlId">
                <el-input v-model="detailForm.oriDtlId" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="原业务类型编码" prop="oriBiztype">
                <el-select
                  style="width: 100%"
                  v-model="
                      detailForm.oriBiztype === null || detailForm.oriBiztype === undefined
                        ? ''
                        : detailForm.oriBiztype + '-' + detailForm.oriBiztypeDesc
                    "                  placeholder="原业务类型编码"
                ></el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="原交易货币" prop="curcd">
                <el-input v-model="detailForm.curcd" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="原交易金额" prop="amount">
                <ht-amount-input v-model="detailForm.amount" placeholder="原交易金额"></ht-amount-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="24">
              <el-form-item label="查询内容" prop="queryContent">
                <el-input type="textarea" v-model="detailForm.queryContent" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="查询录入操作员" prop="queryMdTlrno">
                <el-input v-model="detailForm.queryMdTlrno" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="查询录入时间" prop="queryMdTime">
                <el-date-picker
                  style="width: 100%"
                  v-model="detailForm.queryMdTime"
                  value-format="yyyyMMddHHmmss"
                  type="datetime"
                />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="查询审核操作员" prop="saudTlrno">
                <el-input v-model="detailForm.saudTlrno" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="通信状态" prop="status">
                <el-select style="width: 100%" v-model="detailForm.status" placeholder="通信状态">
                  <el-option
                    v-for="dict in dictMap.PKG_STATUS"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="24">
              <el-form-item label="查询审核附言" prop="saudRemarks">
                <el-input type="textarea" v-model="detailForm.saudRemarks" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="中心状态" prop="procStatus">
                <el-select style="width: 100%" v-model="detailForm.procStatus" placeholder="中心状态">
                  <el-option
                    v-for="dict in dictMap.PROCESSSTATUS"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="业务状态" prop="txnstatus">
                <el-select style="width: 100%" v-model="detailForm.txnstatus" placeholder="业务状态">
                  <el-option
                    v-for="dict in dictMap.TXN_STATUS"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="查询发送时间" prop="querySendtime">
                <el-date-picker
                  style="width: 100%"
                  v-model="detailForm.querySendtime"
                  value-format="yyyyMMddHHmmss"
                  type="datetime"
                />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="查询接收时间" prop="queryRcvtime">
                <el-date-picker
                  style="width: 100%"
                  v-model="detailForm.queryRcvtime"
                  value-format="yyyyMMddHHmmss"
                  type="datetime"
                />
              </el-form-item>
            </el-col>
          </el-row>
        </el-card>

        <el-card class="form-card txnInfo-card">
          <div slot="header" class="label-header-msg">
            <span>业务查复详细信息</span>
          </div>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="查复流水号" prop="id">
                <el-input v-model="rspdetailForm.id" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="通讯状态" prop="status">
                <el-select style="width: 100%" v-model="rspdetailForm.status" placeholder="通讯状态">
                  <el-option
                    v-for="dict in dictMap.PKG_STATUS"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="中心状态" prop="procStatus">
                <el-select style="width: 100%" v-model="rspdetailForm.procStatus" placeholder="中心状态">
                  <el-option
                    v-for="dict in dictMap.PROCESSSTATUS"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="业务状态" prop="txnstatus">
                <el-select style="width: 100%" v-model="rspdetailForm.txnstatus" placeholder="业务状态">
                  <el-option
                    v-for="dict in dictMap.TXN_STATUS"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="查复录入操作员" prop="reviewMdTlrno">
                <el-input v-model="rspdetailForm.reviewMdTlrno" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="查复审核操作员" prop="audTlrno">
                <el-input v-model="rspdetailForm.audTlrno" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="查复录入时间" prop="reviewMdTime">
                <el-date-picker
                  style="width: 100%"
                  v-model="rspdetailForm.reviewMdTime"
                  value-format="yyyyMMddHHmmss"
                  type="datetime"
                />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="报文发送时间" prop="sndTime">
                <el-date-picker
                  style="width: 100%"
                  v-model="rspdetailForm.sndTime"
                  value-format="yyyyMMddHHmmss"
                  type="datetime"
                />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="报文接收时间" prop="rcvTime">
                <el-date-picker
                  style="width: 100%"
                  v-model="rspdetailForm.rcvTime"
                  value-format="yyyyMMddHHmmss"
                  type="datetime"
                />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="24">
              <el-form-item label="查复内容" prop="rspContent">
                <el-input type="textarea" v-model="rspdetailForm.rspContent" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-card>
      </el-form>

      <div slot="footer" align="center" class="dialog-footer">
        <el-button @click="printDetail">打 印</el-button>
        <el-button type="primary" @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { apiUrlConfigQuery, ccmsInquiryQueryDetail } from "@/api/cnaps/ccms/314";
import { listPageMixin } from "@/libs/listPageMixin";
import { amountThousandsFormatter } from "@/utils/table_col_formatter";
import HtAmountInput from "@/views/components/HtAmountInput";
import AmountRangeSearch from "@/views/components/AmountSearchInput";
import { mapGetters } from "vuex";

export default {
  name: "ccmsInquiryQuery",
  mixins: [listPageMixin],
  components: { HtAmountInput, AmountRangeSearch },
  computed: {
    ...mapGetters(["globalBusData"]),
  },
  created() {
    this.$set(this.queryParams, "brno", this.globalBusData.brno);
  },
  watch: {
    globalBusData: {
      handler(val) {
        this.$set(this.queryParams, "brno", val.brno);
      },
      deep: true,
      immediate: true,
    },
  },
  data() {
    return {
      // 查询参数
      queryParams: {
        idSeqNo: undefined,
        brno: undefined,
        sysCode: undefined,
        cpgdate: undefined,
        cpgdate2: undefined,
        workdate: undefined,
        workdate2: undefined,
        drct: undefined,
        status: undefined,
        amount1: undefined,
        amount2: undefined,
        indirectSender: undefined,
        indirectRecver: undefined,
        oriPkgid: undefined,
      },
      // 搜索
      formOptions: [],
      //
      detailForm: {},
      rspdetailForm: {},
      searchFormDictList: [
        "SYS_CODE",
        "DRCTCODE",
        "PKG_STATUS",
        "ORGAN_SYSTYPE_310",
        "INQ_TYPE_314_QUERY",
        "PROCESSSTATUS",
        "TXN_STATUS",
        "Cnaps2Dict.CP2_BRNO",
      ],
      // 列信息
      regConfig: apiUrlConfigQuery,

      tableBindColumns: [
        { prop: "brno", label: "内部机构号", dictCode: "Cnaps2Dict.CP2_BRNO", sortable: false },
        { prop: "status", label: "通讯状态", dictCode: "PKG_STATUS" },
        { prop: "id", label: "查询流水号", width: "180" },
        { prop: "id2", label: "查复流水号", width: "180" },
        { prop: "drct", label: "来往标识", dictCode: "DRCTCODE" },
        { prop: "sysCode", label: "系统编号", dictCode: "SYS_CODE", width: "180" },
        {
          prop: "amount",
          label: "原交易金额",
          type: "price",
          width: "150",
        },
        { prop: "vdate", label: "CPG日期", type: "date" },
        { prop: "workdate", label: "工作日期", type: "date" },
        { prop: "indirectSender", label: "发起间接参与机构", width: "150" },
        { prop: "indirectRecver", label: "接收间接参与机构", width: "150" },
        { prop: "oriPkgid", label: "原报文标识号", width: "180" },
      ],
      dictMapAsync: {},
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      totalRecord: 0,
      totalPage: 0,
      needCount: 0,

      rules: {},
    };
  },
  mounted() {
    this.$refs.amountRangeSearch.$on('getAmountRange',this.beforeSearchCallback);

    const formOptions = [
      // 普通搜索

      {
        type: "input",
        prop: "idSeqNo",
        defaultAttr: {
          size: "small",
          label: "查询流水号",
          placeholder: "请输入查询流水号",
        },
      },
      {
        type: "search-dept-tree",
        prop: "brno",
        defaultAttr: {
          radio: false,
          linkParentChoose: false,
          label: "分行选择",
          placeholder: "请选择分行",
        },
      },
      {
        type: "dict",
        dict: "SYS_CODE",
        prop: "sysCode",
        defaultAttr: {
          size: "small",
          label: "系统编号",
          placeholder: "请输入系统编号",
        },
      },
      {
        type: "input",
        prop: "oriPkgid",
        defaultAttr: {
          size: "small",
          label: "原报文标识号",
          placeholder: "请输入原报文标识号",
        },
      },
      {
        type: "dates",
        nameObj: {
          startTimeName: "cpgdate",
          endTimeName: "cpgdate2",
        },
        defaultAttr: {
          size: "small",
          label: "CPG日期",
          placeholder: ["请输入CPG开始日期", "请输入CPG结束日期"],
          format: "yyyy-MM-dd",
          valueFormat: "yyyyMMdd",
        },
      },

      {
        type: "dates",
        nameObj: {
          startTimeName: "workdate",
          endTimeName: "workdate2",
        },
        defaultAttr: {
          size: "small",
          label: "工作日期",
          placeholder: ["请输入工作开始日期", "请输入工作结束日期"],
          format: "yyyy-MM-dd",
          valueFormat: "yyyyMMdd",
        },
      },

      {
        type: "dict",
        dict: "DRCTCODE",
        prop: "drct",
        defaultAttr: {
          size: "small",
          label: "来往标识",
          placeholder: "请输入来往标识",
        },
      },

      {
        type: "dict",
        dict: "PKG_STATUS",
        prop: "status",
        defaultAttr: {
          size: "small",
          label: "通讯状态",
          placeholder: "请输入通讯状态",
        },
      },

      {
        type: "input",
        prop: "indirectSender",
        defaultAttr: {
          size: "small",
          label: "发起间接参与机构",
          placeholder: "请输入发起间接参与机构",
        },
      },

      {
        type: "input",
        prop: "indirectRecver",
        defaultAttr: {
          size: "small",
          label: "接收间接参与机构",
          placeholder: "请输入接收间接参与机构",
        },
      },
    ];
    this.formOptions = formOptions;
    this.dictMapAsync = this.getDictMap();
  },
  methods: {
    /***
     * 按钮操作汇总
     */
    /***
     * 按钮操作汇总
     */
    handleAction(type, row = {}) {
      switch (type) {
        case "detail":
          this.handleDetail(row);
          break;
      }
    },

    // 关闭按钮
    cancel() {
      this.open = false;
    },

    /** 详情按钮操作 */
    handleDetail(row) {
      this.title = "业务查询信息查询明细";
      let id2 = row.id2 === undefined || row.id2 === null ? "" : row.id2;
      ccmsInquiryQueryDetail(row.id, id2).then((response) => {
        this.detailForm = response.result.data;
        this.rspdetailForm = response.result.rsp;
        if (this.rspdetailForm === undefined || this.rspdetailForm === null) {
          this.rspdetailForm = {};
        }

        this.open = true;
      });
    },

    //打印
    printDetail() {
      this.$print(this.$refs["detailForm"]);
    },

    beforeSearchCallback() {
      // 搜索按钮之前先执行
      this.queryParams.amount1 = this.$refs.amountRangeSearch.getAmount1();
      this.queryParams.amount2 = this.$refs.amountRangeSearch.getAmount2();
    },
    clearCallBack() {
      let that = this;
      return new Promise(function (resolve, reject) {
        that.$refs.amountRangeSearch.clearAmount();
        that.queryParams.amount1 = "";
        that.queryParams.amount2 = "";
      });
    },
  },
};
</script>
<style>
.label-header-msg {
  font-weight: bold;
}

.form-card {
  margin-bottom: 10px;
}
</style>
